import java.util.*;
import java.awt.*;
import javax.swing.*;
import javax.imageio.*;
import java.awt.image.*;
import java.io.File;
import java.awt.event.*;

class GUI{
	static JBuilding jb = new JBuilding();
	static EJCall[] e = new EJCall[6];
	static JFrame f =new JFrame();
	static JPanel p = new JPanel();
	static JPanel p1 = new JPanel();
	static EJChoose ej = new EJChoose(1);
	static EJChoose ej2 = new EJChoose(2);
	static EJChoose ej3 = new EJChoose(3);
	private static int[] index = new int[4];
	public GUI(){
		for(int i=1;i<4;i++) index[i] = 450;
	}
	public static void init(){
		p1.setLayout(new FlowLayout(FlowLayout.LEFT,60,0));
		p1.add(new JLabel("       "));
		p1.add(ej);
		p1.add(ej2);
		p1.add(ej3);
		jb.repaint();
		//p.add(new JLabel(" "));
		for(int i=0;i<6;i++){
			p.add(e[i] = new EJCall(6-i));
			p.add(new JLabel());
		}
		p.setLayout(new GridLayout(6,1));
		f.add(p,BorderLayout.EAST);
		f.add(jb,BorderLayout.CENTER);
		f.add(p1,BorderLayout.NORTH);
		f.setSize(700,650);
		f.setVisible(true);
	}
	public static void move(int id,int floor){
		floor=538-88*floor;
		if(floor>index[id]) while(index[id]++<floor) {
			jb.repaint();
			sleep();
		}
		else while(index[id]-->floor) {
			jb.repaint();
			sleep();	
		}
	}
	private static void sleep(){
		try
		{
			Thread.sleep(25);
		}
		catch(Exception e){

		}
	}
	public static void main(String[] args){
		GUI g = new GUI();
		GUI.init();
		
	}

	static class JBuilding extends JPanel{
	JButton btn = new JButton("test");
	BufferedImage img,ele;
	public JBuilding(){
		try
		{
			img = ImageIO.read(new File("img/b.png"));
			ele = ImageIO.read(new File("img/a.png"));
		}
		catch(Exception e){
			System.out.println("绘画错误！！！");
		}
		
	}
	public void paint(Graphics g){
		g.drawImage(img,110,0,null);
		g.drawImage(ele,180,index[1],null);
		g.drawImage(ele,320,index[2],null);
		g.drawImage(ele,460,index[3],null);
	}
	
}
	
}
class EJCall extends JPanel{
	private JButton bu = new JButton("\u25b2");
	private JButton bd = new JButton("\u02c7");
	private JLabel[] lable = new JLabel[10];
	private int index;

	public EJCall(int x){
		index = x;
		this.setLayout(new GridLayout(4,1));
		//this.setOpaque(false);
		for(int i = 0;i<2;i++) lable[i] = new JLabel("");
		bu.addActionListener(new click("up",index));
		bd.addActionListener(new click("down",index));
		this.add(lable[0]);
		this.add(bu);
		this.add(bd);
	}
	private void init(int x){
		
	}
	private void create(){

	}

}
class EJChoose extends JPanel{
	JButton[] btn = new JButton[6];
	JLabel lable;
	JTextField s = new JTextField();
	JTextField floor = new JTextField();
	int x;
	public EJChoose(int a){
		lable = new JLabel("电梯");
		this.add(new JLabel("   "+a+"号"));
		this.add(lable);
		this.setLayout(new GridLayout(5,2));
		this.setOpaque(true);
		for(int i=0;i<6;i++) {
			this.add(btn[i] = new JButton(i+1+""));
			btn[i].addActionListener(new click(i+1));
		}
		this.add(s);
		this.add(floor);
	}
	public void setText(int x,String str){
		s.setText(" "+x);
		floor.setText(str);
	}
}
